home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / nt / cons.handler.nt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  3.6 KB  |  113 lines

  1. /* Client interface for General purpose NT console save/restore server
  2.    Having the same interface as its Linux counterpart:
  3.        Copyright (C) 1994 Janne Kukonlehto <jtklehto@stekt.oulu.fi> 
  4.    
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2 of the License, or
  8.    (at your option) any later version.
  9.    
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  18.    
  19.    Note:
  20.        show_console_contents doesn't know how to write to its window
  21.        the rest works fine.
  22. */
  23. #ifndef _OS_NT
  24. #error This file is for the NT operating system.
  25. #else
  26.  
  27. #include <config.h>
  28. #include <windows.h>
  29.  
  30. int    cons_saver_pid = 1;
  31.  
  32. #include "tty.h"
  33. #include "util.h"
  34. #include "win.h"
  35. #include "cons.saver.h"
  36.  
  37. signed char console_flag = 1;
  38. static HANDLE hSaved, hNew;
  39.  
  40. void show_console_contents (int starty, int begin_line, int end_line)
  41. {            /* jg: what is starty? */
  42.     DWORD dw;
  43.     COORD c0 = {0,0};
  44.     COORD csize = {COLS, end_line-begin_line}; 
  45.     SMALL_RECT rect = { 0, begin_line, COLS, end_line };
  46.     CHAR_INFO *pchar;
  47.  
  48.  
  49. //    -- This code reads characters and attributes
  50.     pchar = malloc (sizeof(CHAR_INFO) *  (end_line-begin_line) * COLS);
  51.     // Copy from one console to the curses virtual screen
  52.     ReadConsoleOutput (hSaved, pchar, csize, c0, &rect);
  53.  
  54.     // this may work if refresh() is not called - but it is :-(
  55.     WriteConsoleOutput (hNew, pchar, csize, c0, &rect);
  56.     
  57. #ifdef USE_NCURSES        
  58. // Here we read only characters so that we can printw to stdscr.
  59. //    pchar = malloc (sizeof(TCHAR) * (end_line-begin_line) * COLS);
  60.  
  61.     // Copy from one console to the curses virtual screen
  62. //    ReadConsoleOutputCharacter (hSaved, pchar, (end_line-begin_line) * COLS, c0, &dw);
  63.  
  64. //    mvprintw(0, begin_line, "%.*s", (end_line-begin_line) * COLS, pchar);
  65. #else
  66. #error show_console_contents not written for S-Lang
  67. #endif
  68.  
  69.  
  70.     free (pchar);
  71. }
  72.  
  73. void handle_console (int action)
  74. {
  75.     static SECURITY_ATTRIBUTES sa;
  76.     COORD c;
  77.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  78.  
  79.     switch (action){
  80.     case CONSOLE_INIT:            // Init
  81.         hSaved = GetStdHandle (STD_OUTPUT_HANDLE);        // Save Standard handle
  82.  
  83.     sa.bInheritHandle = TRUE;                // Create a new console buffer
  84.     hNew = CreateConsoleScreenBuffer (GENERIC_WRITE | GENERIC_READ, 
  85.                 FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, 
  86.                 CONSOLE_TEXTMODE_BUFFER, NULL);
  87.     GetConsoleScreenBufferInfo(hSaved, &csbi);        // ... with same size 
  88.     SetConsoleScreenBufferSize(hNew, csbi.dwSize);
  89.  
  90.     SetConsoleActiveScreenBuffer(hNew);            // ... that becomes standard handle
  91.     SetStdHandle(STD_OUTPUT_HANDLE, hNew);
  92.     break;
  93.  
  94.     case CONSOLE_DONE:            // Clean Up
  95.         CloseHandle (hNew);
  96.         break;
  97.  
  98.     case CONSOLE_SAVE:            // Save
  99.     SetConsoleActiveScreenBuffer (hNew);            // Current = our standard handle
  100.     SetStdHandle (STD_OUTPUT_HANDLE, hNew);
  101.     break;
  102.  
  103.     case CONSOLE_RESTORE:        // Restore
  104.     SetConsoleActiveScreenBuffer (hSaved);            // Put saved (shell) screen buffer 
  105.     SetStdHandle (STD_OUTPUT_HANDLE, hSaved);
  106.     break;
  107.     default:
  108.     OutputDebugString ("Invalid action code received in handle_console");
  109.     }
  110. }
  111.  
  112. #endif // !_OS_NT
  113.